$(function () {
    //首页轮播
    $.ajax({
        type: "post",
        url: "http://www.rice.com/app/api/h5_access",
        data: {
            method: "loadpic"
        },
        dataType: "json",
        success: function (result) {
            if (result.status == "1") {
                var pic = result.data.picdata;
                // console.log(pic);
                var sttr = '<div class="swiper-wrapper">';
                for (var i in pic) {
                    sttr += ' <div class="swiper-slide">';
                    sttr += '<a href="' + pic[i].url + '">';
                    sttr += '<img src="' + pic[i].img_url + '" width="100%" /></a>';
                    sttr += ' </div>';
                }
                sttr += '</div>';
                $("#d2").html(sttr);
                var mySwiper2 = new Swiper('#d2', {
                    autoplay: 2000, //自动轮播参数
                    loop: true, //无限循环
                    grabCursor: true, //鼠标放上时变成手的形状
                    autoplayDisableOnInteraction: false, //点击屏幕后仍然可以自动播放
                })
            }
        }
    })


    var token = sessionStorage.getItem("token");
    var url = "http://www.rice.com/app/api/h5_access";
    var d = {};
    d.method = "get_user_msg";
    d.token = token;
    //支付
    $.ajax({
        type: "post",
        url: url,
        data: d,
        dataType: "json",
        success: function (result) {
            if (result.status == "1") {
                var data = result.data;
                var login_name = data.login_name;
                var level_name = data.level_name;
                var money = data.money;
                var code_num = data.code_num;
                var img_head = data.img_head;
                var is_set_pwd = data.is_set_pwd;
                var realname_confirm = data.realname_confirm;
                var merchant_confirm = data.merchant_confirm;
                var active_status = data.active_status;
                var has_activity = data.has_activity;
                var act_title = data.act_title;
                var act_level = data.act_level;
                var act_level_name = data.act_level_name;
                var balance = data.balance;
                var recommend = data.recommend;
                var p = "<p style='display:none'>data</p>";
                if (!img_head) {
                    $("#img_head").attr("src", img_head);
                }
                sessionStorage.setItem("login_name", login_name);
                sessionStorage.setItem("level_name", level_name);
                sessionStorage.setItem("user_level", data.user_level);
                sessionStorage.setItem("is_set_pwd", is_set_pwd);
                sessionStorage.setItem("money", money);
                sessionStorage.setItem("recommend", recommend);
                sessionStorage.setItem("code_num", code_num);
                sessionStorage.setItem("img_head", img_head);
                sessionStorage.setItem("realname_confirm", realname_confirm);
                sessionStorage.setItem("merchant_confirm", merchant_confirm);
                sessionStorage.setItem("active_status", active_status);
                sessionStorage.setItem("has_activity", has_activity);
                sessionStorage.setItem("act_title", act_title);
                sessionStorage.setItem("act_level", act_level);
                sessionStorage.setItem("act_level_name", act_level_name);
                sessionStorage.setItem("balance", balance);
                if (is_set_pwd == "0") {
                    var zfm = $("#zfm").html();
                    //页面层
                    layer.open({
                        type: 1,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['420px', '240px'], //宽高
                        content: '<div id="d1"></div>'
                    });
                    $("#d1").html(zfm);
                }
            } else if (result.status == "2") {
                alert(result.message);
                location.href = "login.html";
            } else {
                alert(result.message);
                return false;
            }

        }
    })
})
//智能还款
$("#reim").click(function () {
    var active_status = sessionStorage.getItem("active_status");
    var realname_confirm = sessionStorage.getItem("realname_confirm");
    if (realname_confirm == 0) {
        $("#aaa1").css("display", "block");
        $("#ddd1").css("display", "block");
    } else if (active_status == "0") {
        location.href = "reimbursement.html";
    } else {
        location.href = "reimbursement1.html";
    }
})